/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dal;

import connection.ConnectionDB;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.AnalysisCar;
import model.AnalysisPkType;
import model.AnalysisTour;

/**
 *
 * @author Administrator
 */
public class AnalysisDAL {

    private AnalysisCar anlCar;
    private AnalysisTour anlTour;
    private AnalysisPkType anlPkType;
    private ConnectionDB conn = new ConnectionDB();
    private CallableStatement cs;

    public List<AnalysisCar> listRecordAnalysisCar() {
        try {
            List<AnalysisCar> list = new ArrayList<AnalysisCar>();
            cs = conn.createConnection().prepareCall("{call sp_AnalysisCar}");
            ResultSet rs = cs.executeQuery();

            while (rs.next()) {
                anlCar = new AnalysisCar();
                anlCar.setCarID(rs.getInt("CarID"));
                anlCar.setCarName(rs.getString("CarName"));
                anlCar.setCarPercent(rs.getFloat("Percents"));
                anlCar.setQuantity(rs.getInt("Quantity"));
                anlCar.setTotalPrice(rs.getFloat("Total"));
                list.add(anlCar);
            }
            return list;
        } catch (SQLException ex) {
            Logger.getLogger(AnalysisDAL.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public List<AnalysisTour> listRecordAnalysisTour() {
        try {
            List<AnalysisTour> list = new ArrayList<AnalysisTour>();
            cs = conn.createConnection().prepareCall("{call sp_AnalysisTour}");
            ResultSet rs = cs.executeQuery();

            while (rs.next()) {
                anlTour = new AnalysisTour();
                anlTour.setPackageTourID(rs.getInt("PackageTourID"));
                anlTour.setPackageTourName(rs.getString("PackageTourName"));
                anlTour.setPercent(rs.getFloat("Percents"));
                anlTour.setQuantity(rs.getInt("Quantity"));
                anlTour.setTotalpPrice(rs.getFloat("Total"));
                list.add(anlTour);
            }
            return list;
        } catch (SQLException ex) {
            Logger.getLogger(AnalysisDAL.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public List<AnalysisPkType> listRecordAnalysisPkType() {
        try {
            List<AnalysisPkType> list = new ArrayList<AnalysisPkType>();
            cs = conn.createConnection().prepareCall("{call sp_AnalysisPackagetype}");
            ResultSet rs = cs.executeQuery();

            while (rs.next()) {
                anlPkType = new AnalysisPkType();
                anlPkType.setPackageType(rs.getString("PackageName"));
                anlPkType.setPercent(rs.getFloat("Percents"));
                list.add(anlPkType);
            }
            return list;
        } catch (SQLException ex) {
            Logger.getLogger(AnalysisDAL.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
}
